<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css">
</head>
<body>
<div style="height: 20px"></div>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">设备管理</a>
        <a href="#">添加设备</a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<form  class="layui-form"  id="equipment" onsubmit="return false" style="width:500px;padding-top: 10px">
    <div class="layui-form-item">
        <label class="layui-form-label">设备编号</label>
        <div class="layui-input-block">
            <input type="text" name="number" id="number" lay-verify="number"  placeholder="设备编号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">学校</label>
        <div class="layui-input-block">
            <select name="school_id" id="school_id" style="width: 500px">
                <option value="">请选择学校</option>
                {foreach $school as $info}
                <option value="{$info.school_id}" >{$info.school_name}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">家长</label>
        <div class="layui-input-block">
            <select name="parent_id" id="parent_id" style="width: 500px">
                <option value="">请选择家长</option>
                {foreach $parent as $info}
                <option value="{$info.id}">{$info.phone}</option>
                {/foreach}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">绑定类型</label>
        <div class="layui-input-block">
            <input type="radio" name="type" value="1" title="学校">
            <input type="radio" name="type" value="2" title="家长">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">座位号</label>
        <div class="layui-input-block">
            <input type="text" name="serial_number" id="serial_number" lay-verify="serial_number" placeholder="座位号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">批次号</label>
        <div class="layui-input-block">
            <input type="text" name="device_batch" id="device_batch" lay-verify="device_batch" placeholder="批次号（用于后台）" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="add" lay-submit lay-filter="*">立即添加</button>
            <button id="back" class="layui-btn layui-btn-primary">返回</button>
        </div>
    </div>
</form>
</body>
<script>
    layui.use(['form'],function () {
        var form = layui.form;
        form.verify({
            number: function(value){
                if(!value || value.length != 15){
                    return '设备编号为15位';
                }
            },
            serial_number:function (value) {
                if(!value){
                    return '请输入座位号';
                }
            },
            device_batch:function (value) {
                if(!value){
                    return '请输入批次号';
                }
            },
        });
        form.on('submit(*)', function(data) {
            $.ajax({
                url:"{:url('/equipment/insertEquipment')}",
                data:$("#equipment").serialize(),
                type:"post",
                dataType:"json",
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            window.location.reload();
                        });
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                    }
                }
            });
        });
    })
    // $("#add").click(function(){
    //     if(!$("#number").val()){
    //         layer.msg('设备编号不能为空',{icon:5,time:2000});
    //         return;
    //     }
    //     if(!$("#serial_number").val()){
    //         layer.msg('设备序列号不能为空',{icon:5,time:2000});
    //         return;
    //     }
    //     $.ajax({
    //         url:"{:url('/equipment/insertEquipment')}",
    //         data:$("#equipment").serialize(),
    //         type:"post",
    //         dataType:"json",
    //         success:function(res){
    //             if(res.code){
    //                 layer.msg(res.msg,{icon:1,time:2000},function(){
    //                     window.location.reload();
    //                 });
    //             }else{
    //                 layer.msg(res.msg,{icon:5,time:2000});
    //             }
    //         }
    //     });
    // });
    //返回
    $("#back").click(function () {
        window.history.go(-1);
    })
</script>
</html>